package com.example.wac.controller;

import com.example.wac.annotation.UnJwtToken;
import com.example.wac.service.ExcelService;
import com.example.wac.vo.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author wuancheng
 * @description
 * @date 2022-01-13 15:08:00
 */

@RestController
@RequestMapping("/excel")
public class ExcelController {

    @Autowired
    ExcelService excelService;

    /**
     * 商品数据导出(一次性填充)
     *
     * @param response
     */
    @PostMapping("goods_export")
    public void goodsExport(HttpServletResponse response){
        excelService.goodsExport(response);
    }

    /**
     * 商品数据分页导出(分多次导出)
     *
     * @param response
     */
    @PostMapping("goods_export_page")
    public void goodsExportPage(HttpServletResponse response){
        excelService.goodsExportByPage(response);
    }

    /**
     * 商品数据导出至oss
     *
     * @return
     */
    @PostMapping("goods_export_oss")
    public ApiResult goodsExportOss(){
        return excelService.goodsExportOss();
    }

    /**
     * 商品Excel信息初始化
     *
     * @param response
     * @param file
     * @return
     */
    @PostMapping("goods_init")
    public ApiResult goodsInit(HttpServletResponse response, @RequestParam("file")MultipartFile file){
        return excelService.goodsInit(response,file);
    }

    @UnJwtToken
    @PostMapping("goods_init/workbook")
    public ApiResult goodsInitByWorkbookFactory(HttpServletResponse response, @RequestParam("file") MultipartFile file){
        return excelService.goodsInitByWorkbookFactory(response, file);
    }
}
